<?php
namespace app\payclass\model;

use app\BaseModel;
use think\facade\Db;

class Active extends BaseModel
{
    //定义表名
    protected $name = 'longbing_card_payclass_active';


    protected $append = [

        'class_name'
    ];


    /**
     * @author chenniang
     * @DataTime: 2020-12-09 10:19
     * @功能说明:课程名称
     */
    public function getClassNameAttr($value,$data){

        if(!empty($data['class_id'])){

            $calss_model = new ClassList();

            return $calss_model->where(['id'=>$data['class_id']])->value('title');
        }

    }

    /**
     * @author chenniang
     * @DataTime: 2020-12-08 10:51
     * @功能说明:列表
     */
    public function atvList($dis,$page){

        $data = $this->where($dis)->order('top desc,id desc')->paginate($page)->toArray();

        return $data;

    }


    /**
     * @author chenniang
     * @DataTime: 2020-12-22 09:22
     * @功能说明:后台活动列表
     */
    public function adminAtvList($dis,$page){


        $data = $this->alias('a')
                ->join('longbing_card_payclass_list b','a.class_id = b.id')
                ->where($dis)
                ->field('a.*')
                ->group('a.id')
                ->order('a.top desc,a.id desc')
                ->paginate($page)
                ->toArray();

        return $data;
    }

    /**
     * @author chenniang
     * @DataTime: 2020-10-09 17:05
     * @功能说明:配置详情
     */
    public function atvInfo($dis){

        $data = $this->where($dis)->find();

        return !empty($data)? $data->toArray():[];

    }


    /**
     * @author chenniang
     * @DataTime: 2020-09-29 11:04
     * @功能说明:配置添加
     */
    public function atvAdd($data){

        $data['create_time'] = time();

        $data['update_time'] = time();

        $res = $this->insert($data);

        return $res;

    }



    /**
     * @author chenniang
     * @DataTime: 2020-09-29 11:05
     * @功能说明:配置编辑
     */
    public function atvUpdate($dis,$data){

        $data['update_time'] = time();

        $res = $this->where($dis)->update($data);

        return $res;

    }















}